package net.lzzy.errorpage.controller;

import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

//全局异常处理
//@ControllerAdvice就是@Controller的增强版。@ControllerAdvice主要⽤来处理全局数据，⼀般搭配
//@ExceptionHandler、@ModelAttribute以及@InitBinder使⽤。

@ControllerAdvice//另有@RestControllerAdvice
public class GlobalExceptionHandler {

    //Exception.class表示全局异常
    @ExceptionHandler(Exception.class)
    public String myError(Exception e, Model model){
        model.addAttribute("msg",e.getMessage());
        return "myerror";
    }
}
